<template>
  <div>
    <!--路径导航-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/users' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>活动管理</el-breadcrumb-item>
      <el-breadcrumb-item>活动列表</el-breadcrumb-item>
      <el-breadcrumb-item>活动详情</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card" :body-style="{ padding:'10px'}">
      <el-row :gutter="15">
        <el-col :span="8">
          <div class="grid-content bg-purple">
            <el-input
              placeholder="请输入内容"
              class="input-with-select"
              v-model="queryInfo.query"
              :clearable="true"
              @clear="getGoodsList"
            >
              <el-button slot="append" icon="el-icon-search" @click="getGoodsList()"></el-button>
            </el-input>
          </div>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addGoods">添加商品</el-button>
        </el-col>
      </el-row>
      <el-table :border="true" :data="goodsList">
        <el-table-column type="index" width="50px"></el-table-column>
        <el-table-column prop="goods_name" label="商品名称"></el-table-column>
        <el-table-column prop="goods_price" label="商品价格(元)" width="120px"></el-table-column>
        <el-table-column prop="goods_number" label="商品数量" width="100px"></el-table-column>
        <el-table-column prop="add_time" label="创建时间" width="200px">
          <template v-slot="scope">{{scope.row.add_time|goodsDate}}</template>
        </el-table-column>
        <el-table-column label="操作" width="150px">
          <template v-slot="scope">
            <el-button type="primary" @click="editGoods(scope.row)" size="mini">编辑</el-button>
            <el-button type="danger" @click="deleteGoods(scope.row)" size="mini">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[5,10,15,20,30]"
          :page-size="queryInfo.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>
<script>
export default {
  created() {
    this.getGoodsList();
  },
  data() {
    return {
      goodsList: [],
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5
      },
      total: 0
    };
  },
  methods: {
    async getGoodsList() {
      const { data: res } = await this.$http.get("goods", {
        params: this.queryInfo
      });
      if (res.meta.status != 200) return this.$message.error("获取数据失败");
      this.goodsList = res.data.goods;
      this.total = res.data.total;
    },
    //修改每页显示条数
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.getGoodsList();
    },
    //显示当前页数的信息
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.getGoodsList();
    },
    editGoods() {},
    deleteGoods() {},
    addGoods() {
      this.$router.push("/addGoods");
    }
  }
};
</script>
<style lang="less" scoped>
.el-col .grid-content {
  margin-left: 11px;
}
.el-card .block {
  margin-left: 300px;
}
</style>